﻿
#include <Type/Province.h>

#include "..\Data\User.h"

#include "UserInfo.h"

namespace TC
{
    namespace Request
    {
        Q_INVOKABLE void UserInfo::change(const QString &headUrl,
            const QString &nickname)
        {
            if (status() == Status::Communicating)
                return;
            AbstractRemoteProcedure::get("user/changeInfo",
            {
                { "signature", Data::User::instance()->signature() },
                { "headUrl", headUrl },
                { "nickname", nickname },
            });
        }

        void UserInfo::onDataReady(QDataStream &stream)
        {
            bool result;
            stream >> result;
            if (result)
			{
                QByteArray newSignature;
                stream >> newSignature;

				bool hasTouristPermission;
				bool hasUserPermission;
				bool hasAdminPermission;
                stream >> hasTouristPermission >> hasUserPermission >> hasAdminPermission;

                Data::User::instance()->setSignature(newSignature);
				Data::User::instance()->setIsTourist(hasTouristPermission);
				Data::User::instance()->setIsUser(hasUserPermission);
				Data::User::instance()->setIsAdmin(hasAdminPermission);

                setOk();
            }
            else
                setFailed();
        }
    }
}
